<!--联系人添加-->
<template>
<div class="ne-contacts-add">
  <el-row type="flex" justify="center" class="ne-contacts-block">
    <el-col :span="14">
      <h1 class="text-center ne-contacts-title">请先补充联系人信息</h1>
      <el-form :model="contactsForm" ref="contactsForm" label-width=".6rem" class="ne-contacts-form">
        <el-form-item class="line" label="名称" prop="CONTACT_NAME"
                      :rules="{
                             required: true, message: '名称不能为空', trigger: 'blur'
                           }"
        >
          <el-input v-model="contactsForm.CONTACT_NAME"></el-input>
        </el-form-item>
        <el-form-item class="line" label="电话" prop="MOBILE_PHONE"
                      :rules="[
                             { required: true, message: '请输入手机号码', trigger: 'blur' },
                             { min: 11, max: 11, message: '请输入11位手机号码', trigger: 'blur' },
                             { pattern: /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/,
                              message: '请输入正确的手机号码'
                             }
                            ]"
        >
          <el-input v-model="contactsForm.MOBILE_PHONE"></el-input>
        </el-form-item>
        <el-form-item class="line" label="邮箱" prop="E_MAIL"
                      :rules="[
                        { required: true, message: '请输入邮箱地址', trigger: 'blur' },
                        { type: 'email', message: '请输入正确的邮箱地址', trigger: 'blur' }
                      ]"
        >
          <el-input v-model="contactsForm.E_MAIL"></el-input>
        </el-form-item>
        <el-form-item class="text-center">
          <el-button type="primary" @click="submitForm('contactsForm')">提交</el-button>
          <el-button @click="resetForm('contactsForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </el-col>
  </el-row>
</div>
</template>

<script>
import OrderService from "@/api/order/OrderService.js";
import {mapState} from 'vuex';
export default {
  name: "ContactsAdd",
  data(){
    return{
    }
  },
  props:{
    contactsJson:{
      type: Object,
      default(){
        return {}
      }
    },
    contactsForm:{
        type: Object,
        default(){
          return {
            CONTACT_NAME:'',
            MOBILE_PHONE:'',
            E_MAIL:''
          }
        }
    },
    allParams:{
      type: Object
    }
  },
  computed:{
    ...mapState('user',['user'])
  },
  mounted() {
  },
  created() {},
  components:{
  },
  methods:{
    // 提交
    async submitForm(formName) {
      
      this.$refs['contactsForm'].validate((valid) => {
        if (valid) {
          // 成功
          
          this.addContacts();
        } else {
          
          return false;
        }
      });
    },
    // 重置
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    // 添加联系人service
    async addContacts(){
      let params = {
        saveCust: {
          contFlag: false,//固定的
          commonRegionId: this.user.orgId,//session里面取
          // commonRegionId: '500182954', // 临时
          addFlag: 'order',   //固定的
          // staffId: '1', // 临时
          staffId: this.user.staffId,
          returnjson: encodeURI(JSON.stringify(this.contactsJson), "utf-8"),
          ...this.contactsForm
        },
        qryCust: this.allParams,
      }
      
      const result =await OrderService.saveInterFaceCust(params);
      
      if(~~result.meta.resultCode==0){
        this.openDialog('添加成功','','success');
        this.$emit('addContactResult',result);
      }else{
        this.openDialog('添加失败',result.meta.resultMsg,'error');
      }
    },
    // 提示
    openDialog(title,msg,type) {
      this.$notify({
        title: title,
        message: msg,
        type: type
      });
    }
  }
}
</script>

<style lang="scss" scoped>
.ne-contacts-add{
  .ne-contacts-block {
    width: 70%;
    border: 1px solid #ebebeb;
    border-radius: 3px;
    padding: .2rem;
    margin: .1rem auto;
    .ne-contacts-title{
      color: #fa6731;
      font-size: $fontSize_v2;
      padding:.05rem 0 .1rem 0;
      font-weight: 500;
    }
  }
}
</style>
